package com.xunwulian.dubbo.service.impl;

import com.xunwulian.api.dto.BaseResponse;
import com.xunwulian.api.iface.SubscriberAPI;
import com.xunwulian.base.dao.SubscriberDao;
import com.xunwulian.base.entity.SubscriberEntity;
import org.apache.ibatis.annotations.Param;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.alibaba.dubbo.config.annotation.Service;

/**
 * Created by liyankai on 2017/3/13.
 */
@Service
public class SubscriberApiImpl implements SubscriberAPI {

    protected static final Logger logger = LoggerFactory.getLogger(SubscriberApiImpl.class);

    @Autowired
    private SubscriberDao subscriberDao;

    public SubscriberApiImpl() {
    }

    @Override
    public void add(SubscriberEntity subscriberEntity) {
        subscriberDao.insert(subscriberEntity);
    }

    @Override
    public BaseResponse<SubscriberEntity> findByOpenId(@Param("openId") String openId) {
        BaseResponse response = new BaseResponse();
        response.setData(subscriberDao.findByOpenId(openId));

        return response;
    }

    @Override
    public void bind(@Param("userId") String userId, @Param("openId") String openId) {
        subscriberDao.bind(userId, openId);
    }

    @Override
    public void unbind(@Param("openId") String openId) {
        subscriberDao.unbind(openId);
    }
}
